<template>
  <div class="exReview-container">
    <el-calendar v-model="calendarDate">
      <template slot="dateCell" slot-scope="{ date, data }">
        <div class="boxExReview" @click="handleClick(date, data)">
          <p :class="data.isSelected ? 'is-selected' : ''">
            {{ data.day.split("-").slice(2).join("-") }}
          </p>
          <!-- <div class="header">
            <i class="el-icon-delete" @click="handledele(date, data)"></i>
          </div> -->
          <div v-for="(item, index) in calendarData" :key="index">
            <div class="textContent itemgreen" v-if="item.rbSj == data.day" >
              <!-- <div>
                <p class="item2">{{ item.overCount }}</p>
              </div> -->
            </div>
          </div>
        </div>
      </template>
    </el-calendar>
    <el-dialog
      :visible.sync="dialogTableVisible"
      :close-on-click-modal="false"
      width="80%"
      @open="handleDialogOpen"
    >
      <exReviewQuery ref="childExReview" :dateTransfer="parentdate" />
    </el-dialog>
  </div>
</template>

<script>
import { calendarlist } from "@/api/system/daily";
import exReviewQuery from "@/components/daily/exReviewQuery";
export default {
  components: {
    exReviewQuery,
  },
  //   props: {
  //     receivetype: {
  //       type: String,
  //     },
  //   },
  data() {
    return {
      // 传递日期给子组件
      parentdate: "",
      calendarDate: "",
      form: {
        takeCount: null,
        id: null,
      },
      dialogTableVisible: false,
      calendarData: [],
      // 设置一个月提交一次收货数量
      year: "",
      month: "",
      number: "",
    };
  },
  created() {
    this.$nextTick(() => {
      const prevBtn = document.querySelector(
        ".el-calendar__button-group .el-button-group>button:nth-child(1)"
      );
      const nextBtn = document.querySelector(
        ".el-calendar__button-group .el-button-group>button:nth-child(3)"
      );
      const handleButtonClick = (e) => {
        console.log(e);
        const preDate = new Date(this.calendarDate);
        let year = preDate.getFullYear();
        let month = preDate.getMonth() + 1;
        let currDate = `${year}-${month}`;
        console.log(currDate);
      };
      // 点击前一个月
      prevBtn.addEventListener("click", handleButtonClick);
      // 点击下一个月
      nextBtn.addEventListener("click", handleButtonClick);
      // 点击本月
      let nowBtn = document.querySelector(
        ".el-calendar__button-group .el-button-group>button:nth-child(2)"
      );
      nowBtn.addEventListener("click", (e) => {
        console.log(e, this.calendarDate);
        const currentDate = new Date();
        let year = currentDate.getFullYear();
        let month = currentDate.getMonth() + 1;
        let currDate = `${year}-${month}`;
        console.log(currDate);
      });
    });
  },
  mounted() {
    this.getlistData();
  },
  methods: {
    handleDialogOpen() {
      this.$nextTick(()=>{
        this.$refs.childExReview.handleExreviewSearch();
      })
    },
    getlistData() {
      calendarlist({ type: "外复核" }).then((res) => {
        this.calendarData = res.data.datas;
      });
    },
    handleClick(date, dataValue) {
      this.dialogTableVisible = true;
      this.parentdate = dataValue.day;
      console.log(this.parentdate);
    },
  },
};
</script>

<style lang="scss" scoped>
.exReview-container {
  position: relative;
  padding: 6px;
}
.is-selected {
  color: #1989fa;
  font-size: 14px;
}
::v-deep .data-show {
  background: #9be2db;
  border: 5px double #fff;
  border-radius: 5px;
  width: 60% !important;
  margin: 0 auto;
}
::v-deep .el-calendar-table .el-calendar-day {
  height: 130px !important;
}
::v-deep .el-calendar-table thead th{
    padding: 0;
}
::v-deep .el-calendar__header {
    padding: 0 20px;
}
.boxExReview {
  position: relative;
  font-weight: 700;
  font-size: 14px;
  width: 100%;
  height: 100%;
  // overflow: hidden;
  p {
    position: absolute;
  }
  .header {
    position: absolute;
    top: 4%;
    left: 92%;
    z-index: 999;
    ::v-deep .el-icon-delete:before {
      color: #141414;
    }
  }
  .textContent {
    line-height: 25px;
    width: 100%;
    height: 110px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 3px 3px 16px;
  }
  .itemgreen {
    width: 100%;
    height: 114px;
    background: #80f886;
    border-radius: 10px;
  }
  .itemgraw {
    width: 100%;
    height: 114px;
    background: #8a898991;
    border-radius: 10px;
  }
}
.box .textContent .item1 {
  color: rgb(25, 27, 27);
}
.box .textContent .item2 {
  color: #4bcffa;
}
.box .textContent .item3 {
  color: #0984e3;
}
::v-deep .el-dialog {
  width: 28%;
}
::v-deep .el-input__inner {
  width: 100%;
}
// ::v-deep .el-dialog__body {
//   padding: 15px 20px !important;
//   width: 400px;
// }
::v-deep .el-calendar__title {
  font-size: 20px;
}
::v-deep .el-button-group > .el-button:last-child {
  font-size: 14px;
}
::v-deep .el-button-group > .el-button:not(:first-child):not(:last-child) {
  font-size: 14px;
}
::v-deep .el-button-group > .el-button:first-child {
  font-size: 14px;
}
::v-deep .el-calendar__body {
  padding: 4px 20px 35px !important;
}
.optionItem {
  position: absolute;
  top: 15px;
  left: 160px;
  display: flex;
  .setYear {
    margin-left: 10%;
    display: flex;
    .el-date-editor.el-input {
      width: 120px;
      margin-right: 10px;
    }
  }
  .setNumber {
    margin-left: 10px;
    display: flex;
    align-items: center;
    .text {
      display: block;
      width: 120px;
    }
  }
  ::v-deep .el-button {
    width: 100px;
    margin-left: 10px;
  }
}
</style>